<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计数器</title>
</head>

<body>
    <!-- 要挂载的节点 -->
    <div id="root"></div>
    <!-- 引入依赖 -->
    <script src="../lib/react.js"></script>
    <script src="../lib/react-dom.js"></script>
    <script src="../lib/babel.js"></script>
    <!-- 设置类型为text/babel 否则浏览器无法解析jsx -->
    <script type="text/babel">
        // 1.定义app组件
        class App extends React.Component {
            constructor() {
                super()
                this.state = {
                    title: "哈哈哈",
                    imgURL: "https://ts1.cn.mm.bing.net/th/id/R-C.95bc299c3f1f0e69b9eb1d0772b14a98?rik=W5QLhXiERW4nLQ&riu=http%3a%2f%2f20178405.s21i.faiusr.com%2f2%2fABUIABACGAAgoeLO-wUo4I3o2gEw8Qs4uAg.jpg&ehk=N7Bxe9nqM08w4evC2kK6yyC%2bxIWTjdd6HgXsQYPbMj0%3d&risl=&pid=ImgRaw&r=0",
                    isActive: true,
                    objStyle: {
                        color: "red",
                        fontsize: "30px"
                    }
                }
            }

            render() {
                const { title, imgURL, isActive, objStyle } = this.state
                // 1.class绑定的写法一：字符串拼接
                const className = `abc cba ${isActive ? "active" : ''}`
                
                // 2.class绑定的写法二：将所有的class放到数组中
                const classList = ['abc', 'cba']
                if (isActive) classList.push("active")
                // 3.class绑定的写法三：第三方库classnames

                return (
                    <div>
                        { /* 1.基本属性绑定 */}
                        <h2 title={title}>我是h2元素</h2>
                        <img src={imgURL} alt="" />
                        { /* 2.绑定class属性 */}
                        <h2 className={classList.join(" ")}></h2>
                        { /* 3.绑定style属性 */}
                        <span style={objStyle}>呵呵呵呵呵</span>
                    </div>
                )
            }
        }
        // 2.创建root并且渲染App组件
        const root = ReactDOM.createRoot(document.querySelector("#root"))
        root.render(<App />)
    </script>
</body>

</html>